package com.ruoyi.web.controller.gouhuoruku;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.goods.domain.Shangpinxinxi;
import com.ruoyi.goods.service.IShangpinxinxiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gouhuoruku.domain.GouhuoRuku;
import com.ruoyi.gouhuoruku.service.IGouhuoRukuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购货入库Controller
 *
 * @author ruoyi
 * @date 2023-05-22
 */
@Api(tags="入库单据管理")
@RestController
@RequestMapping("/system/ghrk")
public class GouhuoRukuController extends BaseController
{
    @Autowired
    private IGouhuoRukuService gouhuoRukuService;

    @Autowired
    private IShangpinxinxiService shangpinxinxiService;

    /**
     * 查询购货入库列表
     */
    @ApiOperation("查询入库单据列表")
//    @PreAuthorize("@ss.hasPermi('system:ghrk:list')")
    @GetMapping("/list")
    public TableDataInfo list(GouhuoRuku gouhuoRuku)
    {
        startPage();
        List<GouhuoRuku> list = gouhuoRukuService.selectGouhuoRukuList(gouhuoRuku);
        return getDataTable(list);
    }

    /**
     * 导出购货入库列表
     */
//    @PreAuthorize("@ss.hasPermi('system:ghrk:export')")
    @Log(title = "购货入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GouhuoRuku gouhuoRuku)
    {
        List<GouhuoRuku> list = gouhuoRukuService.selectGouhuoRukuList(gouhuoRuku);
        ExcelUtil<GouhuoRuku> util = new ExcelUtil<GouhuoRuku>(GouhuoRuku.class);
        util.exportExcel(response, list, "购货入库数据");
    }

    /**
     * 获取购货入库详细信息
     */
    @ApiOperation("查询入库单据详细信息")
//    @PreAuthorize("@ss.hasPermi('system:ghrk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gouhuoRukuService.selectGouhuoRukuById(id));
    }

    /**
     * 新增购货入库
     */
    @ApiOperation("新增入库单据")
//    @PreAuthorize("@ss.hasPermi('system:ghrk:add')")
    @Log(title = "购货入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GouhuoRuku gouhuoRuku)
    {
        gouhuoRuku.setGouhuoJingshouren(getLoginUser().getUser().getNickName());
        return toAjax(gouhuoRukuService.insertGouhuoRuku(gouhuoRuku));
    }

    /**
     * 修改购货入库
     */
    @ApiOperation("修改入库单据")
//    @PreAuthorize("@ss.hasPermi('system:ghrk:edit')")
    @Log(title = "购货入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GouhuoRuku gouhuoRuku)
    {
        return gouhuoRukuService.updateGouhuoRuku(gouhuoRuku);
    }

    /**
     * 删除购货入库
     */
    @ApiOperation("删除入库单据")
//    @PreAuthorize("@ss.hasPermi('system:ghrk:remove')")
    @Log(title = "购货入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gouhuoRukuService.deleteGouhuoRukuByIds(ids));
    }


    @GetMapping("/SpList")
    public TableDataInfo SpList(Shangpinxinxi shangpinxinxi)
    {
//        startPage();
        List<Shangpinxinxi> list = shangpinxinxiService.selectShangpinxinxiList(shangpinxinxi);
        return getDataTable(list);
    }

}
